package by.ins.task;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Deprecated /* will be deleted*/
public class TaskManager {
	public static final org.apache.log4j.Logger log = org.apache.log4j.LogManager.getLogger(TaskManager.class);
	
	private static TaskManager taskManager;
	
	private Map<Long , Task> tasks =  new HashMap<Long, Task>();
	
	public static TaskManager getTaskManager(){
		if (taskManager == null){
			taskManager = new TaskManager();			
		}
		return taskManager;
	}
	
	private static long lastTaskId = 0;
	
	private List<Thread> threads; 
	
	public static final long generateTaskID(){
		return lastTaskId++;
	}	
	
	public void run(Long taskId ){
		Task task = tasks.get(taskId);
		task.doTask();		
	}
	
	public void stop(Long taskId ){
		((ManagedTask) get(taskId) ).cancel();
	}
	
	public void pause(Long taskId ){		
			((ManagedTask)get(taskId)).pause();		
	}

	public void pause(Long taskId , long ms  ){
		((ManagedTask)get(taskId)).pause(ms);
	}
	
	public void continueT(Long taskId ){
		((ManagedTask)get(taskId)).continueT();
	}

	public void addTask(Task task) {
		tasks.put(task.getId(), task );		
	}
	
	private Task get(long taskId){
		return tasks.get(taskId);
	}
	
	public List<Task> getAllTasks(){
		return new ArrayList<Task>( tasks.values());
	}
	
	public Task getTask(long id){
		return tasks.get(id);
	}

}
